$(function(){
	new Vue({
		el:"#editShopApplyApp",
		data:{
			fullscreenLoading:false,
			dialogFormVisible:false,
			formLabelWidth:"180px",
			form:{
			   reason:"",	
			   uid:"",
			},
			tableData: []
		},
		created:function(){
		   this.updateShopList()
		},
		methods:{
			updateShopList(){
				this.fullscreenLoading = true;
				let param = {
					page: 1,
				}
				axios({
					url: POSTURL.updateShopList,
					method:'post',
					data: param
				}).then(response => {
					this.fullscreenLoading = false;
					if (response.data.code === 100) {
					  this.tableData = [];
					    for(let obj  of response.data.result){
							 let value = {};
							  value.logoImg =  obj.newShop.logoImg
							  value.name  = obj.newShop.name
							  value.uid = obj.newShop.uid
							  value.phoneNum = obj.newShop.phoneNum
							  value.cardBackImg = obj.oldShop.cardBackImg
							  value.cardFrontImg = obj.oldShop.cardFrontImg
							  value.corpName  = obj.oldShop.corpName
							  this.tableData.push(value)
						}
					} else {
						this.$message.error(response.data.message);
					}
				}).catch(error => {
					this.fullscreenLoading = false;
					console.log(error);
					this.$message.error('服务器出错!');
				})
			},
			handleEdit(val){
				 this.changeShopInfo(val.uid,0)
			},
			handleDelete(val){
				this.form.uid   = val.uid
				this.dialogFormVisible = true
			},
			changeShopInfo(uid,status){
				this.fullscreenLoading = true;
				let param = {
					uid:uid,
					updateState:status
				}
				if (status == 2){
					param.updateCause = this.form.reason
				}
				axios({
					url: POSTURL.setRebate,
					method: 'post',
					data: param
				}).then(response => {
					this.fullscreenLoading = false;
					if (response.data.code === 100) {
						  this.updateShopList()
						  if(status === 2){
							  this.form = {}
						  }
					} else {
						this.$message.error(response.data.message);
					}
				}).catch(error => {
					this.fullscreenLoading = false;
					console.log(error);
					this.$message.error('服务器出错!');
				}) 
			},
			configRefuse(){
				this.dialogFormVisible = false
				this.changeShopInfo(this.form.uid,2)
			}
		    
		}
	})
})